'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _collapse = require('antd/lib/collapse');

var _collapse2 = _interopRequireDefault(_collapse);

var _radio = require('antd/lib/radio');

var _radio2 = _interopRequireDefault(_radio);

var _row = require('antd/lib/row');

var _row2 = _interopRequireDefault(_row);

var _col = require('antd/lib/col');

var _col2 = _interopRequireDefault(_col);

var _select = require('antd/lib/select');

var _select2 = _interopRequireDefault(_select);

var _utils = require('../utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var Panel = _collapse2['default'].Panel;

var RadioButton = _radio2['default'].Button;
var RadioGroup = _radio2['default'].Group;

var EditorState = function (_Component) {
  (0, _inherits3['default'])(EditorState, _Component);

  function EditorState() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3['default'])(this, EditorState);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = EditorState.__proto__ || Object.getPrototypeOf(EditorState)).call.apply(_ref, [this].concat(args))), _this), _this.onChange = function (e) {
      _this.props.onChange('cursor', e);
    }, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret);
  }

  (0, _createClass3['default'])(EditorState, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      var _props = this.props,
          showClassState = _props.showClassState,
          locale = _props.locale,
          isMobile = _props.isMobile,
          value = _props.value,
          onChange = _props.onChange,
          props = (0, _objectWithoutProperties3['default'])(_props, ['showClassState', 'locale', 'isMobile', 'value', 'onChange']);

      var childrenToRender = Object.keys(locale.styleSelect).map(function (key) {
        var item = locale.styleSelect;
        if (isMobile && item[key] === 'hover') {
          return null;
        }
        return _react2['default'].createElement(
          RadioButton,
          { value: key, key: key, className: 'ant-radio-button-auto-width' },
          item[key]
        );
      }).filter(function (c) {
        return c;
      });
      return _react2['default'].createElement(
        Panel,
        (0, _extends3['default'])({}, props, { header: props.header || locale.header }),
        _react2['default'].createElement(
          _row2['default'],
          { gutter: 8 },
          _react2['default'].createElement(
            _col2['default'],
            { span: 24 },
            locale.cursor
          )
        ),
        _react2['default'].createElement(
          _row2['default'],
          { gutter: 8 },
          _react2['default'].createElement(
            _col2['default'],
            { span: 24 },
            _react2['default'].createElement(
              _select2['default'],
              {
                style: { width: '100%' },
                value: value.cursor || 'auto',
                size: 'small',
                onChange: this.onChange,
                getPopupContainer: function getPopupContainer(node) {
                  return (0, _utils.getParentNode)(node, 'editor-list');
                },
                dropdownMatchSelectWidth: false,
                dropdownClassName: 'editor-list-dropdown'
              },
              (0, _utils.getOption)(locale.cursorSelect, true)
            )
          )
        ),
        showClassState && [_react2['default'].createElement(
          _row2['default'],
          { gutter: 8, key: '0' },
          _react2['default'].createElement(
            _col2['default'],
            { span: 24 },
            locale.style
          )
        ), _react2['default'].createElement(
          _row2['default'],
          { gutter: 8, key: '1' },
          _react2['default'].createElement(
            _col2['default'],
            { span: 24 },
            _react2['default'].createElement(
              RadioGroup,
              {
                value: value.classState,
                size: 'small',
                onChange: function onChange(e) {
                  _this2.props.onChange('classState', e.target.value);
                }
              },
              childrenToRender
            )
          )
        )]
      );
    }
  }]);
  return EditorState;
}(_react.Component);

EditorState.propTypes = {
  value: _propTypes2['default'].object,
  onChange: _propTypes2['default'].func,
  header: _propTypes2['default'].string,
  locale: _propTypes2['default'].object,
  showClassState: _propTypes2['default'].bool,
  isMobile: _propTypes2['default'].bool
};
EditorState.defaultProps = {
  value: {},
  onChange: function onChange() {}
};
exports['default'] = EditorState;


EditorState.componentName = 'EditorState';
module.exports = exports['default'];